package com.ecode.sample.event;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author wqh
 * @date 2022年07月30日 22:52
 */
@Slf4j
@Component
public class MsgListener  {

    @Async
    @SneakyThrows
    @EventListener(MsgEvent.class)
    public void onApplicationEvent(MsgEvent event) {
        String msg = event.getMsg();
        log.info("接收消息：{}",msg);
        long start = System.currentTimeMillis();
        log.info("发送短信：{}",msg);
        log.info("发送邮件：{}",msg);
        Thread.sleep(5000);
        long end = System.currentTimeMillis();
        log.info("{}：发送短信、邮件耗时：({})毫秒", msg, (end - start));
    }
}
